﻿define(function (require, exports, module) {

    var IReader_InstanceEventHandler = FXREADER.Event.IReader_InstanceEventHandler;
    var Interface = FXREADER.Interface;

    var CVerfyForward_InstanceEventHandler = function () {
        var _successCallBack = null;
        var _successData = null;
        var _self = this;
        var      _Language = FXREADER.AppInstance.GetLanguage();

        var _reVerifyForward = function (jqPassword, jqErrInfo) {
            var t_psd = jqPassword.val();
            if (t_psd == null) return;
            t_psd = escape(t_psd);
            var data = { fileid: FXREADER.AppInstance.GetFileID(), psd: t_psd };
            function _ParseCallBack(error) {
                if (error == 8)
                    jqErrInfo.html("<font color='red'>" + _Language.ParseError.PasswordIncorrect + "</font>");

            }
            _self.VerfyForward(data, false, _self._successCallBack, _self._successData, _ParseCallBack);
        }

        this.VerfyForward = function (data, bFirst, successCallBack, successData, parseCallBack) {
            this._successCallBack = successCallBack;
            this._successData = successData;
            $.ajax({
                url: FXREADER.Config.Url.VerifyForward,
                type: 'POST',
                dataType: 'json',
                data: data,
                success: function (response) {
                    var error = response.error;
                    parseCallBack && parseCallBack(error);
                    if (error != 0) {
                        error == 8 && bFirst && FXREADER.ConfirmPassword("", _Language.ParseError.EnterPassword, _reVerifyForward);
                    }
                    else {
                        try {
                            FXREADER.EndConfirmPassword();
                            _self._successCallBack(_self._successData);
                        }
                        catch (ex) {
                            throw ex; // new Error('Init App Error!');
                            return false;
                        }

                    }


                }
            });
        }
    };

    CVerfyForward_InstanceEventHandler.prototype = {
        //WebReader实例化之前进行的操作的事件
        OnBeforeInstance: function (callback, data) {
            var data1 = { fileid: FXREADER.AppInstance.GetFileID() };
            this.VerfyForward(data1, true, callback, data);
        },

        //WebReader退出程序之前进行的操作的事件
        OnExitInstance: function (callback, data) { }
    };

    FXREADER.Event.CVerfyForward_InstanceEventHandler = CVerfyForward_InstanceEventHandler;
    return FXREADER.Event.CVerfyForward_InstanceEventHandler;


});